{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "612e9ebc",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-09-20\n",
    "* 课程： Python语言\n",
    "* week03\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60f4578f",
   "metadata": {},
   "source": [
    "# 本周学习内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3216eb6",
   "metadata": {},
   "source": [
    "> 1. 模块与函数\n",
    "> 2. 变量、赋值、数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82fc5f3a",
   "metadata": {},
   "source": [
    "## 1. 模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1aaf05b1",
   "metadata": {},
   "source": [
    "> 1. 标准库\n",
    "> 2. 开源模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c67dc550",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 标准库实践\n",
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "36eb79b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'win32'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.platform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a5e71ec6",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'time' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m time\u001b[38;5;241m.\u001b[39mlocaltime\n",
      "\u001b[1;31mNameError\u001b[0m: name 'time' is not defined"
     ]
    }
   ],
   "source": [
    "time.localtime"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50431c7a",
   "metadata": {},
   "source": [
    "* 笔记\n",
    "> 如上错误，在使用某一个模块前，需要先import该模块，否则会出现：NameError: name 'time' is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "90c747f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9e3a7da3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=11, tm_mday=14, tm_hour=23, tm_min=54, tm_sec=17, tm_wday=1, tm_yday=318, tm_isdst=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "664958e0",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pyecharts'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[6], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 开源模块实践\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpyecharts\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyecharts'"
     ]
    }
   ],
   "source": [
    "# 开源模块实践\n",
    "import pyecharts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a4bb37d",
   "metadata": {},
   "source": [
    "* 笔记\n",
    "> 下载安装开源模块方法：pip install module_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1de72cec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Collecting pyecharts\n",
      "  Obtaining dependency information for pyecharts from https://files.pythonhosted.org/packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531C150>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n",
      "  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531C8D0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n",
      "  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531D050>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n",
      "  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531D850>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n",
      "  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531DF90>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata\n",
      "ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/88/9c/213d7107634fb6629a932f9120ec78be04435eabd1b2bee482908ac9d648/pyecharts-2.0.4-py3-none-any.whl.metadata (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000016C5531E6D0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8d15f72c",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pyecharts'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpyecharts\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyecharts'"
     ]
    }
   ],
   "source": [
    "import pyecharts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dee8c81b",
   "metadata": {},
   "source": [
    "# 2. 使用一个模块（函数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b964adf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1452b78a",
   "metadata": {},
   "outputs": [],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "381a7b86",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help 可以查看一个  模块  的帮助文档\n",
    "# help(time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c659c91e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help 可以查看一个  函数 的帮助文档（使用文档）\n",
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2e8afa7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world~\n"
     ]
    }
   ],
   "source": [
    "time.sleep(5)\n",
    "print(\"hello world~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18183024",
   "metadata": {},
   "source": [
    "# 3. 变量、赋值、数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "47c8d19d",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_name = \"豆豆\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "85e61201",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "豆豆\n"
     ]
    }
   ],
   "source": [
    "print(dog_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "69d2f7d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_age = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "36d6b3e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(dog_age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2e154d6d",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_name = \"毛毛\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1b5f2cd3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "毛毛\n"
     ]
    }
   ],
   "source": [
    "print(dog_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "181f1fb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小明 小明\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "name_10001 = \"小明\"\n",
    "\n",
    "name_10002 = name_10001\n",
    "print(name_10001,name_10002)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0fb7b770",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_10001 = \"小兰\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "de4b87dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小兰 小明\n"
     ]
    }
   ],
   "source": [
    "print(name_10001,name_10002)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97295054",
   "metadata": {},
   "source": [
    "# 条件判断 与 循环遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "97bc2f63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，你的身份信息不对，无法开门~\n"
     ]
    }
   ],
   "source": [
    "if dog_name == \"花花\":\n",
    "    print(\"欢迎回家~\")\n",
    "else:\n",
    "    print(\"对不起，你的身份信息不对，无法开门~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6913b37a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
